import 'package:pt_manage/db/base/dao_base.dart';
import 'package:pt_manage/model/site_user_info.dart';

class SiteUserInfoDao extends DaoBase<SiteUserInfo> {
  SiteUserInfoDao() : super(tableName: "site_user_info", createSql: """
      CREATE TABLE IF NOT EXISTS site_user_info (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        siteId INTEGER,
        site TEXT,
        userId TEXT,
        level TEXT,
        uploaded REAL DEFAULT 0,
        downloaded REAL DEFAULT 0,
        shareRate REAL DEFAULT 0,  -- 存储 JSON 格式的标签数组
        publishNum REAL DEFAULT 0,
        publishNum REAL DEFAULT 0,
        seedNum REAL DEFAULT 0,
        seedVolume REAL DEFAULT 0,
        bonus REAL DEFAULT 0,
        integral REAL DEFAULT 0,
        timeBonus REAL DEFAULT 0,
        timeBonus REAL DEFAULT 0,
        inboundTime TIMESTAMP,
        createTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updateTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP    
      );
      CREATE TRIGGER IF NOT EXISTS trigger_site_user_info_updated_at AFTER UPDATE ON site_user_info
      BEGIN
          UPDATE site_user_info SET updateTime = CURRENT_TIMESTAMP WHERE rowid == NEW.rowid;
      END;
    """);

  @override
  SiteUserInfo fromJson(Map<dynamic, dynamic> json) {
    return SiteUserInfo.fromJson(json);
  }

  @override
  int getId(SiteUserInfo obj) {
    return obj.id!;
  }

  @override
  Map<String, dynamic> toJson(SiteUserInfo obj) {
    return obj.toJson();
  }
}
